<?php
$app = Blyn::app()->getActiveApp();
$eventList = $app->getEventList();
$page = $control;
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
?>
<link rel="stylesheet" type="text/css"
      href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap-datetimepicker.min.css" />
<script  type="text/javascript"
         src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-datetimepicker.min.js"/>

<script type="text/javascript">
    $(function() {
        $("#checkAll_2").click(function() {
            $('input[name="subBox"]').attr("checked", this.checked);
        });
        var $subBox = $("input[name='subBox']");
        $subBox.click(function() {
            $("#checkAll").attr("checked", $subBox.length == $("input[name='subBox']:checked").length ? true : false);
        });
    });</script>
<script type="text/javascript">
    $(function() {
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
        $('.tree li.parent_li > span').on('click', function(e) {
            var children = $(this).parent('li.parent_li').find(' > ul > li');
            if (children.is(":visible")) {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            } else {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
            e.stopPropagation();
        });
    });</script>
<script type="text/javascript">
    $(function() {
        $("#Event_Shop_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = '';
            document.getElementById("Event_Clothes_CX_View").style.display = 'none';
        });
        $("#Event_Clothes_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = 'none';
            document.getElementById("Event_Clothes_CX_View").style.display = '';
        });
    });</script>
<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "post-form-2",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>

<div><legend><?php echo $control->getAjaxLink(array('name' => '活动列表', 'id' => 'showEventList'), array('htmlOptions' => array('enctype' => 'multipart/form-data')));?></legend></div>
<fieldset>
    <table class="table table-hover">
        <thead>
            <tr>
                <th><input type="checkbox" name="checkAll_2" id="checkAll_2"></th>
                <th>微活动名称</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>操作</th>
            </tr> 
        </thead>
        <tbody>
            <?php foreach ($eventList as $id=>$event) { ?>
                <tr>
                    <td><label class="checkbox">
                            <input type="checkbox" name="subBox[]" value="<?php echo $event->id; ?>"> 
                        </label></td>
                    <td> <?php echo $event->getName();  ?> </td>
                    <td> <?php echo $event->startTime; ?> </td>
                    <td> <?php echo $event->endTime; ?> </td>
                    <td>
                        <div class="row-fluid">
                            <a href="#myModal<?php echo $event->id; ?>" role="button" data-toggle="modal">修改</a>
                            &nbsp;|&nbsp;
                            <?php 
                                $eventType = $event->getGroup(array('parent' => BWEventGroup::EVENT_TYPE))->name;
                                switch($eventType)
                                {
                                    case '品牌优惠': $messageListView = 'brandList'; break;
                                    case '投票活动': $messageListView = 'poolsList'; break;
                                    default : $messageListView = 'messageList';
                                }
                                echo $control->getAjaxLink(array('name' => '活动内容', 'id' => 'showMessageList'), array('parentEventId' => $event->id,'messageListView'=>$messageListView,'htmlOptions' => array('enctype' => 'multipart/form-data')));
                            ?>
                        </div>
                            <?php                            
                            $modalPage = new BUIControl('addEvent'.$event->id);
                            $modalPage->addRenderView('modalPage', 'addEvent', array('eventId' => $event->id, 'form' => $form));
                            $modalPage->render();
                            ?> 
                    </td>
                </tr>
            <?php } ?>
        </tbody>
    </table>

    <div class="row-fluid">
        <a href="#myModal0" role="button" data-toggle="modal" class="btn">添加</a>
        <?php
        echo $control->getAjaxLink(array('name' => '删除', 'id' => 'deleteEvent'), array('htmlOptions' => array('class' => 'btn', 'enctype' => 'multipart/form-data')));
        ?>
    </div>
    
    <?php
    $modalPage = new BUIControl('addEvent0');
    $modalPage->addRenderView('modalPage', 'addEvent', array('eventId' => 0, 'form' => $form));
    $modalPage->render();
    ?>   

    <div><input type="hidden" name="curPageNo" value="1"></div>

    <div class="pagination">  
        <ul>  
            <li class="active">
                <a href="javascript:void()">前一页</a>    </li>  
            <li class="active">
                <a href="javascript:void()">1</a>    </li>  
            <li class="active">
                <a href="javascript:void()">后一页</a>    </li>  
        </ul>  
    </div>
    <?php $this->endWidget(); ?>


